#ifndef PARTICLE_H
#define PARTICLE_H

//#include "HandMeasureFunction.h"
#include "ParticleSwarm.h"
#include <vector>
#include "Random.h"

using namespace std;

class ParticleSwarm;
class FunctionBase;

class Particle
{
private:
	//------------------------------------------------------
	// Max range
	double Max(vector<double> position);

	//------------------------------------------------------
	// Min range
	double Min(vector<double> position);

protected:
	double pBestCost;		// Personal best cost (fitness) of the particle
	Random _rnd;			// Random number generator 

public:
	//------------------------------------------------------
	///	Swarm
	ParticleSwarm* Swarm;

	//------------------------------------------------------
	///	Position
	vector<double> pPosition;

	//------------------------------------------------------
	///	Velocity
	vector<double> pVelocity;

	//------------------------------------------------------
	///	Cost
	double pCost;

	//------------------------------------------------------
	///	Personal best position of the Particle 
	vector<double> pBestPosition;

	//------------------------------------------------------
	///	Indexers, returns the position of the particle at a certain dimension
	//double& operator[](int i);


	//------------------------------------------------------
	/// Constructors
	Particle();
	Particle(ParticleSwarm* swarm, vector<double> position, vector<double> velocity);

	//------------------------------------------------------
	/// Destructor
	~Particle();

	//------------------------------------------------------
	///	Calculate the cost (fitness)
	void CalculateCost();
	void update_Data(double pCostValue,bool forceUpdate);

	//------------------------------------------------------
	// Update the personal best cost and position of a particle
	void UpdatePBest();

	//------------------------------------------------------
	/// Update the velocity and Position of a particle
	void UpdateVelocityAndPosition(vector<double> bestPositionOfSwarm);
};

#endif